﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.OleDb;
using System.Data.SqlClient;

namespace CFSystem.JXC
{
    public class SimpleFactory
    {
        public SimpleFactory() { }

        /**/
        /// <summary>返回抽象的ConnectionFactory工場對象</summary> 
        public static ConnectionFactory GetConnFactory(string connString, string dbType)
        {
            ConnectionFactory factory;
            switch (dbType.ToUpper())
            {
                case "SQL":
                    //factory = new DBFactory.SqlConnection(connString);

                    factory = new SqlConnection(connString);
                    break;
                case "ACCESS":
                   // factory = new DBFactory.AccessConnection(connString);
                    factory = new AccessConnection(connString);
                    break;
                default:
                    factory = null;
                    break;
            }
            return factory;
        }

        /**/
        /// <summary>返回抽象的CommandFactory工場對象</summary> 
        public static CommandFactory GetCommFactory(IDbConnection conn, string commText, string dbType)
        {
            CommandFactory factory;
            switch (dbType.ToUpper())
            {
                case "SQL":
                    factory = new SqlCommand(conn, commText);
                   
                    break;
                case "ACCESS":
                    factory = new AccessCommand(conn, commText);
                    break;
                default:
                    factory = null;
                    break;
            }

            return factory;
        }

        /**/
        /// <summary>返回抽象的DataAdapterFactory工場對象</summary> 
        public static DataAdapterFactory GetDataAdapterFactory(IDbCommand comm, string dbType)
        {
            DataAdapterFactory factory;
            switch (dbType.ToUpper())
            {
                case "SQL":
                    factory = new SqlDataAdapter(comm);
                    break;
                case "ACCESS":
                    factory = new AccessDataAdapter(comm);
                    break;
                default:
                    factory = null;
                    break;
            }
            return factory;
        }
    } 

}
